<template>
  <div>
  <p style="font-size:12px" class="bgfff mtrbl20 ptrbl20"><span style="font-weight: bold;font-size: 14px;">数据来源说明：</span>连续无收入个体户或临登。</p>
  <div class="app-container">
    <el-row :gutter="20">
      <!--用户数据-->
      <el-col :span="24" :xs="24">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="连续几个月" prop="noIncomeMonth" label-width="90px">
            <el-input-number v-model="queryParams.noIncomeMonth" controls-position="right" :min="1" style="width: 100px"/>
          </el-form-item>
          <el-form-item label="管理企业" prop="companyAdminId" label-width="100px">
            <el-select v-model="queryParams.companyAdminId" value-key="companyId" placeholder="请选择" clearable filterable size="" @change="change">
              <el-option
                v-for="dict in enterpriseDropDownOptions"
                :key="dict.companyId"
                :label="dict.companyName"
                :value="dict.companyId"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="客户企业" prop="companyId" v-if="isShow">
            <el-select v-model="queryParams.companyId" placeholder="请选择" clearable size="" filterable>
              <el-option
                v-for="dict in clientCompany"
                :key="dict.companyId"
                :label="dict.companyName"
                :value="dict.companyId"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="姓名" prop="realName">
            <el-input
              v-model="queryParams.realName"
              placeholder="请输入姓名"
              clearable
              size=""
              style="width: 200px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="证件号" prop="idNumber">
            <el-input
              v-model="queryParams.idNumber"
              placeholder="请输入证件号"
              clearable
              size=""
              style="width: 200px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="手机号" prop="phone">
            <el-input
              v-model="queryParams.phone"
              placeholder="请输入手机号"
              clearable
              size=""
              style="width: 200px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="medium" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="medium" @click="resetQuery">重置</el-button>
          </el-form-item>
          <el-form-item>
            <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="medium"
            @click="handleBatchExport"
            v-hasPermi="['taxmsg:noincome:noIncomeDownload']"
          >导出数据</el-button>
          <el-button
              type="info"
              plain
              icon="el-icon-upload2"
              size="medium"
              @click="handleImport"
              v-hasPermi="['taxmsg:noincome:noIncomeImport']"
            >导入数据</el-button>
            <el-button
              type="primary"
              plain
              icon="el-icon-refresh-right"
              size="medium"
              @click="handleInit"
              v-hasPermi="['taxmsg:noincome:noIncomeInit']"
            >初始化</el-button>
          </el-form-item>
        </el-form>

        <!-- <el-row :gutter="10" class="mb10">
          <el-col :span="1.5">
          </el-col>
          <el-col :span="1.5">
          </el-col>
       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row> -->

        <el-table v-loading="loading" :data="noincomeList">
          
          <el-table-column fixed label="序号" prop="" width="55" align="center">
            <template slot-scope="scope">
              <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
            </template>
          </el-table-column>
          <el-table-column fixed label="姓名" align="left" key="name" prop="name" width="130"/>
          <el-table-column label="证件号" align="left" key="idNumber" prop="idNumber" width="200"/>
          <el-table-column label="手机号" align="left" key="phone" prop="phone" width="130" />
          <el-table-column label="个体户名称" align="left" key="enterpriseName" prop="enterpriseName" width="350"/>
          <el-table-column label="统一社会信用代码" align="left" key="taxNo" prop="taxNo" width="200"/>
          <el-table-column label="纳税人类型" align="left" key="typeName"prop="typeName" width="130"/>
          <el-table-column label="是否已注销" align="left" prop="closeStatus" :formatter="closeFormat" width="130"/>
          <el-table-column label="注册状态" align="left" prop="registerStatus" :formatter="registerFormat"/>
          <el-table-column label="管理企业" align="left" key="companyAdminName" prop="companyAdminName" width="250"/>
          <el-table-column label="客户企业" align="left" key="companyName" prop="companyName" width="250"/>
          <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width" width="100">
            <template slot-scope="scope">
              <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleEdit(scope.row)"
              v-hasPermi="['taxmsg:noincome:noIncomeUpdate']"
            >编辑</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>
    <!-- 编辑状态对话框 -->
    <el-dialog :title="title" :visible.sync="opennoincomeUpdate" width="550px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="是否已注销" prop="closeStatus">
          <el-select
            v-model="form.closeStatus"
            placeholder="全部"
            clearable
            size="small"
          >
            <el-option label="是" value="true"></el-option>
            <el-option label="否" value="false"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input type="textarea" v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancelnoincomeUpdate">取 消</el-button>
      </div>
    </el-dialog>
    <!-- Excel导入数据对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" slot="tip">
          <el-link type="info" style="font-size:12px" @click="importTemplate">下载模板</el-link>
        </div>
        <div class="el-upload__tip" style="color:red" slot="tip">提示：仅允许导入“xls”或“xlsx”格式文件！</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
  </div>
</template>

<script>
import { noincomeList, noincomeUpdate, noIncomeDownload, noincomeInit } from "@/api/taxmsg/noincome";
import { getToken } from "@/utils/auth";
export default {
  name: "Noincome",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 弹出层标题
      title: "",
      // 用户表格数据
      noincomeList: null,
       // 所有的管理企业和关联客户企业信息数据字典
      enterpriseDropDownOptions: [],
      clientCompany:[],
      // 是否显示弹出层（编辑状态）
      opennoincomeUpdate: false,
      // 是否显示弹出层
      form: {},
      open: false,
      isShow:false,
      // Excel导入数据参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 设置上传的请求头部
        headers: { Authorization:getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/tax/income/monthly/noIncome/import"
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        noIncomeMonth: 6,
        companyAdminId: undefined,
        companyId: undefined,
        realName: undefined,
        idNumber: undefined,
        phone: undefined
      },
      // 编辑状态表单校验
      rules: {
        closeStatus: [
          { required: true, message: "请选择是否已注销", trigger: "blur" }
        ]
      }
     
    };
  },
  created() {
    this.getList();
    this.getEnterpriseDropDown().then(response => {
      this.enterpriseDropDownOptions = response.data;
    });
  },
  methods: {
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      noincomeList(this.queryParams).then(response => {
          this.noincomeList = response.data.list;
          this.total = response.data.total;
          this.loading = false;
        }
      );
    },
    change(e){
      delete this.queryParams.companyId
      if(e){
        this.isShow = true;
        this.clientCompany = this.enterpriseDropDownOptions.filter(item => item.companyId === e)[0].clientCompany;
      }else{
        this.isShow = false
      }
    },
    // 状态字典翻译
    closeFormat(row, column) {
      let status = row.closeStatus;
      switch (status) {
        case true:
        status = "已注销";
          break;
        case false:
        status = "未注销";
          break;
      }
      return status;
    },
    registerFormat(row, column) {
      let status = row.registerStatus;
      switch (status) {
        case 0:
        status = "未注册";
          break;
        case 1:
        status = "进行中";
          break;
        case 2:
        status = "已注册";
          break;
        case 3:
        status = "注销中";
          break;
        case 4:
        status = "已注销";
          break;  
      }
      return status;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      //this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
      this.isShow = false;
    },
    cancelnoincomeUpdate() {
      this.opennoincomeUpdate = false;
      this.reset();
    },
    reset() {
      this.form = {
        closeStatus: undefined,
        remark: undefined
      };
      this.resetForm("form");
    },
    /** 编辑状态按钮操作 */
    handleEdit(row) {
      this.reset();
      this.form.taxNo= row.taxNo;

      if(row.closeStatus==false){
        this.form.closeStatus = "否";
      }else if(row.closeStatus==true){
        this.form.closeStatus = "是";
      }

      this.opennoincomeUpdate = true;
      this.title = "编辑";
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if(this.form.closeStatus == "否"){
            this.form.closeStatus = "false"
          }else if(this.form.closeStatus == "是"){
            this.form.closeStatus = "true"
          }
          noincomeUpdate(this.form).then(response => {
              this.msgSuccess(response.msg);
              this.opennoincomeUpdate = false;
              this.getList();
            });
        }
      });
    },
    //初始化
    handleInit(){
      this.$confirm('是否手动初始化无收入数据，确定后会生成连续无收入个体或临登的数据', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return noincomeInit();
        }).then(response => {
          this.getList();
          this.msgSuccess(response.msg);
        }).catch(()=>{})
    },
    // 取消按钮
    cancel() {
      this.open = false;
    },
    /** 导出按钮操作 */
    handleBatchExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return noIncomeDownload(queryParams);
        }).then(response => {
          //this.download(response.msg);
          var list_name = "连续6个月无收入数据";
          this.export_excel_file(response, list_name);
        }).catch(()=>{})
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "导入修改无收入数据";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      // importTemplate().then(response => {
      //   this.download(response.msg);
      // });
      window.location.href = process.env.VUE_APP_BASE_API + "/tax/public/excel/noIncomeImportTpl.xlsx";
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      //alert(response.code);
      this.$alert(response.data.message, "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    }
  }
};
</script>
<style scoped lang="scss">
</style>